package com.xinyue.ext.root;

import java.util.HashMap;
import java.util.Map;

import com.xinyue.ext.data.EntityData;
import com.xinyue.ext.data.RootData;

public class BeanRoot extends RootContext{
	//私有构造器
	private BeanRoot() {
	}
	//私有内部类
	private static class SingletonHolder{
        private static BeanRoot instance = new BeanRoot();  
    }
	/***
	 * 获得实例对象
	 */
	public static BeanRoot getInstance() {
		return SingletonHolder.instance;
	}
	
	/**
	 * 创建Bean数据
	 */
	@Override
	public void freemarkerData(EntityData entity, RootData data) {
		Map<String, Object> root = new HashMap<String, Object>();
		
		root.put("package", entity.getBeanPackage());
		root.put("import", entity.getImports());
		root.put("className", entity.getClassName());
		root.put("table", entity.getTable());
		root.put("id", entity.getId());
		root.put("field", entity.getFields());

		String path = pathBuild(entity.getBeanPackage(), entity.getClassName(), bean_);
		data.setBeanPath(path);
		data.setBeanData(root);
	}
}
